package com.clss.uvctest;

import android.content.Context;
import android.content.SharedPreferences;

import com.google.gson.Gson;

/**
 * SharedPreferences帮助类，保存用户信息等内容
 * Created by LiuV on 2017/6/12.
 */

public class SpHelper {

    private static final String TAG = "SpHelper";

    private static final String PROJECT_NAME = "uvc_text";

    private static final String TOKEN = "token";
    private static final String NAME = "name";
    private static final String ID = "id";
    private static final String USER_NAME = "user_name";
    private static final String PHONE = "phone";
    private static final String USER_ID = "user_id";
    private static final String IS_VERIFY = "is_verify";
    private static final String BIRTH = "birthday";
    private static final String ROLE = "role";


    private static final String FIRE_INSPECTION_ROLE = "fire_inspection_role";

    private static final String LAST_VERSION_CHECK_TIME = "last_version_check_time";

    private static final String SHARE_COMMON_ARRAY = "share_commmon_array";

    private static final String CHAT_MESSAGE_HISTORY = "chat_message_history";

    private static final String SERVICE_HOST = "service_host";

    private static final String FUNCTION_SWITCH_CLUE_STATUS = "clue_status";
    private static final String FUNCTION_SWITCH_FIREALARM_STATUS = "fireAlarm_status";
    private static final String FUNCTION_SWITCH_ALARM_STATUS = "alarm_status";
    private static final String FUNCTION_SWITCH_SAFE_STATUS = "safe_status";
    private static final String FUNCTION_SWITCH_REGISTER_WITH_ROLE_STATUS = "register_with_role_status";

    private static final String INSPECTION_TASKS_BEAN_LIST = "inspection_tasks_bean_list";

    private static final String INVITATION_CODE = "invitation_code";
    private static final String INVITATION_CODE_STATUS = "invitation_code_status";

    private static final String UNLOCK_IDENTITY = "unlock_identity";
    private static final String UNLOCK_AREA_CODE = "unlock_area_code";
    private static final String UNLOCK_AREA_CODE_LAST = "unlock_area_code_last";
    private static final String UNLOCK_AREA_NAME = "unlock_area_name";

    private SharedPreferences mSharedPreferences;

    private static SpHelper spHelper;

    public static SpHelper getInstance(){
        if (spHelper == null){
            synchronized (SpHelper.class){
                if (spHelper == null){
                    spHelper = new SpHelper();
                    return spHelper;
                }
            }
        }
        return spHelper;
    }

    private SpHelper(){
        this(UVCtestApplication.getAppContext(), Context.MODE_PRIVATE);
    }

    private SpHelper(Context context, int mode){
        mSharedPreferences = context.getSharedPreferences(PROJECT_NAME, mode);
    }

    public boolean putString(String key, String value){
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putString(key, value);
        return editor.commit();
    }

    public String getString (String key){
        return mSharedPreferences.getString(key, "");
    }

    public boolean putInt(String key, int value){
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putInt(key, value);
        return editor.commit();
    }

    public int getInt (String key){
        return mSharedPreferences.getInt(key, -1);
    }

    public boolean putLong(String key, long value){
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putLong(key, value);
        return editor.commit();
    }

    public long getLong (String key){
        return mSharedPreferences.getLong(key, -1);
    }


    public boolean putBoolean(String key, boolean value){
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putBoolean(key, value);
        return editor.commit();
    }

    public boolean getBoolean (String key){
        return mSharedPreferences.getBoolean(key, false);
    }

   public String getToken(){
        return getString(TOKEN);
    }

   public int getRole(){
        return getInt(ROLE);
    }
  /*  public boolean setToken(String value){
        return putString(TOKEN, value);
    }


//    public boolean setName(String name){
//        return putString(USER_NAME, name);
//    }

   /* public String getName(){
        return getString(USER_NAME);
    }*/

//    public boolean setPhone(String phone){
//        return putString(PHONE, phone);
//    }

    /*public String getPhone(){
        return getString(PHONE);
    }

    public String getUserId() {
        return getString(USER_ID);
    }*/

//    public boolean setUserId(String userId){
//        return putString(USER_ID, userId);
//    }



    public boolean setIsVerify(int isVerify){
        return putInt(IS_VERIFY, isVerify);
    }

    public boolean setToken(String token){
        return putString(TOKEN, token);
    }
    public boolean setRole(int role){
        return putInt(ROLE, role);
    }

    public int getIsVerify(){
        return getInt(IS_VERIFY);
    }

    public String getUserId(){
        return getString(USER_ID);
    }

    public boolean setUserId(String userId){
        return putString(USER_ID, userId);
    }

    public String getUserName(){
        return getString(USER_NAME);
    }

    public String getName(){
        return getString(NAME);
    }

    public String getPhone(){
        return getString(PHONE);
    }

    public String getBirth(){
        return getString(BIRTH);
    }

    public long getLastVersionCheckTime(){
        return getLong(LAST_VERSION_CHECK_TIME);
    }

    public void setLastVersionCheckTime(long time){
        putLong(LAST_VERSION_CHECK_TIME, time);
    }

    public boolean setShareCommonArray(String shareArray){
        return putString(SHARE_COMMON_ARRAY, shareArray);
    }

    public String getShareCommonArray(){
        return getString(SHARE_COMMON_ARRAY);
    }

    public String getImServerHost() {
        return getString(SERVICE_HOST);
    }

    public boolean setImServerHost(String host) {
        return putString(SERVICE_HOST, host);
    }

    public boolean setClueStatus(boolean status){
        return putBoolean(FUNCTION_SWITCH_CLUE_STATUS, status);
    }
    public boolean getClueStatus(){
        return getBoolean(FUNCTION_SWITCH_CLUE_STATUS);
    }

    public boolean setFireAlarmStatus(boolean status){
        return putBoolean(FUNCTION_SWITCH_FIREALARM_STATUS, status);
    }
    public boolean getFireAlarmStatus(){
        return getBoolean(FUNCTION_SWITCH_FIREALARM_STATUS);
    }

    public boolean setAlarmStatus(boolean status){
        return putBoolean(FUNCTION_SWITCH_ALARM_STATUS, status);
    }

    public boolean getAlarmStatus(){
        return getBoolean(FUNCTION_SWITCH_ALARM_STATUS);
    }

    public boolean setSafeStatus(boolean status){
        return putBoolean(FUNCTION_SWITCH_SAFE_STATUS, status);
    }

    public boolean getSafeStatus(){
        return getBoolean(FUNCTION_SWITCH_SAFE_STATUS);
    }

    public boolean setRegisterWithRoleStatus(boolean status){
        return putBoolean(FUNCTION_SWITCH_REGISTER_WITH_ROLE_STATUS, status);
    }

    public boolean getRegisterWithRoleStatus(){
        return getBoolean(FUNCTION_SWITCH_REGISTER_WITH_ROLE_STATUS);
    }

    public void clearFunctionStatus(){
        setFireAlarmStatus(false);
        setAlarmStatus(false);
        setClueStatus(false);
        setSafeStatus(false);
    }

    public boolean setInvitationCode(String code){
        return putString(INVITATION_CODE, code);
    }

    public String getInvitationCode(){
        return getString(INVITATION_CODE);
    }

    public boolean setInvitationCodeStatus(boolean status){
        return putBoolean(INVITATION_CODE_STATUS, status);
    }

    public boolean getInvitationCodeStatus(){
        return getBoolean(INVITATION_CODE_STATUS);
    }

    public int getUnlockIdentity() {
        return getInt(UNLOCK_IDENTITY);
    }
    public boolean setUnlockIdentity(int identity) {
        return putInt(UNLOCK_IDENTITY,identity);
    }
    public String getUnlockAreaCode() {
        return getString(UNLOCK_AREA_CODE);
    }
    public boolean setUnlockAreaCode(String areaCode) {
        return putString(UNLOCK_AREA_CODE,areaCode);
    }
    public String getUnlockAreaCodeLast() {
        return getString(UNLOCK_AREA_CODE_LAST);
    }
    public boolean setUnlockAreaCodeLast(String areaCode) {
        return putString(UNLOCK_AREA_CODE_LAST,areaCode);
    }
    public String getUnlockAreaNameLast() {
        return getString(UNLOCK_AREA_NAME);
    }
    public boolean setUnlockAreaNameLast(String areaName) {
        return putString(UNLOCK_AREA_NAME,areaName);
    }

    Gson mGson = new Gson();
    public boolean setFireInspectionRole(String fireInspectionRole){
        return putString(FIRE_INSPECTION_ROLE,fireInspectionRole);
    }
    public String getFireInspectionRole() {
        return getString(FIRE_INSPECTION_ROLE);
    }



}
